//package com.firechatwebclient.filter;
//
//import com.book.entity.User;
//import jakarta.servlet.FilterChain;
//import jakarta.servlet.ServletException;
//import jakarta.servlet.annotation.WebFilter;
//import jakarta.servlet.http.HttpFilter;
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//import jakarta.servlet.http.HttpSession;
//
//import java.io.IOException;
//
//@WebFilter("/*")
//public class MainFilter extends HttpFilter {
//    //进行过滤，如果session里面有这个用户就登录，如果没有就拦截
//    @Override
//    protected void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain) throws IOException, ServletException {
//        String url = req.getRequestURL().toString();
//        //当浏览器请求的既不是login页面，或者请求url中不包括staitc的，就拦截
//        if(!url.contains("/static/") && !url.endsWith("login")){
//            HttpSession session = req.getSession();
//            User user = (User) session.getAttribute("user");
//            if(user == null){
//                res.sendRedirect("login");
//                return;
//            }
//        }
//        chain.doFilter(req,res);
//    }
//}
